#include <iostream> 
#include <vector> 
#include <string> 
#include <cstdlib> 
using namespace std; 
const int BOARD_SIZE = 15; 
enum State 
{ 
	EMPTY = 0, 
	BLACK = 1, 
	WHITE = 2 
}; 
void displayBoard(const vector<vector<State>>& board) 
{ 
	cout << "   "; 
	for (int i = 0; i < BOARD_SIZE; ++i) 
	{ 
		printf("%2d ", i + 1); 
	} 
	cout << endl; 
	for (int i = 0; i < BOARD_SIZE; ++i) 
	{ 
		printf("%2d ", i + 1); 
		for (int j = 0; j < BOARD_SIZE; ++j) 
		{ 
			if (board[i][j] == EMPTY) 
			{ 
				cout << ". "; 
			} 
			else if (board[i][j] == BLACK) 
			{ 
				cout << " ● "; 
			} 
			else if (board[i][j] == WHITE) 
			{ 
				cout << " ○ "; 
			} 
		} 
	cout << endl; 
	} 
} 
bool checkWin(const vector<vector<State>>& board, int x, int y, State player) 
{ 
	int dx[] = {1, 0, 1, 1}; 
	int dy[] = {0, 1, 1, -1}; 
	for (int d = 0; d < 4; ++d) 
	{ 
		int count = 1; 
		for (int step = 1; step <= 4; ++step) 
		{ 
			int nx = x + step * dx[d]; 
			int ny = y + step * dy[d]; 
			if (nx >= 0 && nx < BOARD_SIZE && ny >= 0 && ny < BOARD_SIZE && board[nx][ny] == player) 
			{ 
				count++; 
			} 
			else 
			{ 
				break; 
			} 
		} 
		for (int step = 1; step <= 4; ++step) 
		{ 
			int nx = x - step * dx[d]; 
			int ny = y - step * dy[d]; 
			if (nx >= 0 && nx < BOARD_SIZE && ny >= 0 && ny < BOARD_SIZE && board[nx][ny] == player) 
			{ 
				count++; 
			} 
			else 
			{ 
				break; 
			} 
		} 
		if (count >= 5) 
		{ 
			return true; 
		} 
	} 
	return false; 
} 
int main() 
{ 
	vector<vector<State>> board(BOARD_SIZE, vector<State>(BOARD_SIZE, EMPTY)); 
	State currentPlayer = BLACK; 
	cout << "欢迎来到五子棋游戏！" << endl; 
	cout << "玩家1: 黑棋 (●)，玩家2: 白棋 (○)" << endl; 
	while (true) 
	{ 
		system("cls"); 
		displayBoard(board); 
		cout << (currentPlayer == BLACK? "黑棋 (●)" : "白棋 (○)") << " 请落子 (行 列): "; 
		int x, y; 
		bool validMove = false; 
		while (!validMove) 
		{ 
			cin >> x >> y; 
			if (x < 1 || x > BOARD_SIZE || y < 1 || y > BOARD_SIZE) 
			{ 
				cout << "输入位置超出棋盘范围，请重新输入！" << endl; 
			} 
			else if (board[x - 1][y - 1]!= EMPTY) 
			{ 
				cout << "该位置已有子，请重新选择！" << endl; 
			} 
			else 
			{ 
				validMove = true; 
			} 
		} 
		board[x - 1][y - 1] = currentPlayer; 
		if (checkWin(board, x - 1, y - 1, currentPlayer)) 
		{ 
			system("cls"); 
			displayBoard(board); 
			cout << (currentPlayer == BLACK? "黑棋 (●)" : "白棋 (○)") << " 获胜！游戏结束。" << endl; 
			break; 
		} 
		currentPlayer = (currentPlayer == BLACK)? WHITE : BLACK; 
	} 
	return 0; 
}